<?php
namespace App\Http\Controllers;
use App\Repository\Contracts\MemberIntegralInterface;
use App\Support\Helper\CommonHelper;
use Illuminate\Http\Request;
use Auth;

/**
 * @Author:: HuangYin
 * @DateTime: 2017-01-17 19:47
 *
 * @Description: 会员积分
 */
class MemberIntegralController extends Controller
{
    /**
     * @var Request
     */
    protected $request;

    /**
     * @var MemberIntegralInterface
     */
    protected $memberIntegral;

    protected $uid;

    /**
     * MemberIntegralController constructor.
     * @param Request $request
     * @param MemberIntegralInterface $memberIntegral
     */
    public function __construct(Request $request, MemberIntegralInterface $memberIntegral)
    {
        $this->request = $request;

        $this->memberIntegral = $memberIntegral;

        $this->uid = CommonHelper::getToken(Auth::user())['uid'];
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function index()
    {
        $limit = $this->request->input('limit', 15);
        $page = $this->request->input('page', 1);
        $uid = $this->request->input('uid', null);
        //Search Map
        $searchMap = $this->searchMap([
            ['uid', $uid, '=']
        ]);
        $list = $this->memberIntegral->lists($limit, $page, $searchMap);

        return $this->success($list);
    }

    /**
     * @param $id
     * @return \Illuminate\Http\JsonResponse
     */
    public function detail($id)
    {
        $detail = $this->memberIntegral->detail($id);

        return $this->success($detail);
    }
}